﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SingletonUnit
{
    /// <summary>
    /// 线程安全(同步操作,影响系统的瓶颈和额外的开销)
    /// </summary>
    public class ThreadSafeSingleton : BaseSingleton
    {
        private static ThreadSafeSingleton _instance = null;
        private static readonly object SynObject = new object();
        private ThreadSafeSingleton() { }
        public static ThreadSafeSingleton Instance
        {
            get
            {
                lock (SynObject)
                {
                    return _instance ?? (_instance = new ThreadSafeSingleton());
                }
            }
        }
    }
}
